package it.unibo.imola.parser.visitor.entity;

public class DilateStatement extends BuiltinCallStatement {

	public DilateStatement(ToolBox toolbox) {
		super("DILATE", toolbox);
	}
	
	@Override
	public boolean check(GlobalEnvironment gEnv, Environment env) throws Exception {
		if(!super.check(gEnv, env))
			return false;
		Object ap2 = actualParametersList.get(2); // rows
		Object ap3 = actualParametersList.get(3); // cols
		Object ap4 = actualParametersList.get(4); // shape
//		Object ap5 = actualParametersList.get(5); // iterations
		
		if(ap2 instanceof Integer){
			if((Integer)ap2 <= 0 || ((Integer)ap2 % 2) == 0){
				throw new Exception("rows <= 0 || (rows % 2) == 0");
			}
		}
		if(ap3 instanceof Integer){
			if((Integer)ap3 <= 0 || ((Integer)ap3 % 2) == 0){
				throw new Exception("cols <= 0 || (cols % 2) == 0");
			}			
		}
		if(ap4 instanceof Integer){
			if((Integer)ap4 < 0 || (Integer)ap4 > 2){
				throw new Exception("shape can be only '0' (RECTANGLE) or '1' (CROSS) or '2' (ELLIPSE)");
			}			
		}
//		if(ap5 instanceof Integer){
//			if((Integer)ap5 <= 0 ){
//				throw new Exception("cols <= 0 || (cols % 2) == 0");
//			}			
//		}
		return true;
	}

}
